# 1、做一个学生点名系统，系统里支持：存入学生、更改学生、删除学生、点到学生姓名方法
#
# 存入学生（姓名、年龄、家庭地址、手机号）： 存入成功后，提示xxx存入成功
# 更改学生（姓名、年龄、家庭地址、手机号）：可以修改学生内容的任意一个字段
# 删除学生：删除的学生将不在展示
# 展示全部学生：可以看到全部的学生姓名
#  学生姓名：随机抽取任意一个存在的学生信息，然后打印：到！。举例： 刘闯到！
#
# 以上内容，需要连接数据库，每次的数据都需要增、删、改、查去做
#
# student表：name、age、address、phone_number
class students():
    def __init__(self):
        import pymysql
        self.__db = pymysql.connect(host="123.249.78.43",user='root',password='123456',database="wave",
                                  cursorclass=pymysql.cursors.DictCursor) # todo：创建数据库对象
        self.__cursor = self.__db.cursor() # 创建游标
    def __close(self): # todo：方法内部关闭数据库，私有方法
        self.__cursor.close()
        self.__db.close()
    def insert_student_information(self,name,age,address,phone_number):
        self.__cursor.execute("insert into student values" + "('" + name + "','" + str(age) + "','" + address + "','" + str(phone_number) + "')")
        self.__db.commit()  # 涉及到增、删、改，都必须要提交数据库
        self.__close() # 关闭数据库
    def update_student_information(self,old_name,new_name,age,address,phone_number):
        self.__cursor.execute(
                "update student set " + "name=" + "'" + new_name + "'," +"age="  + str(age)  +",address=" + "'" + address + "',"
                   + "phone="+ str(phone_number) +" where name=" + "'" +old_name + "'" )
        self.__db.commit()  # 涉及到增、删、改，都必须要提交数据库
        self.__close()  # 关闭数据库
    def delete_student_information(self,name):
        self.__cursor.execute("delete from student where name = " +"'" +name + "'" )
        self.__db.commit()  # 涉及到增、删、改，都必须要提交数据库
        self.__close()  # 关闭数据库
    def show_student(self):
        self.__cursor.execute("select * from student")
        result = self.__cursor.fetchall()
        self.__close()
        return result
    def point_to_student(self):
        self.__cursor.execute("select * from student")
        result = self.__cursor.fetchall()
        student_name_list = []
        for i in result:
            student_name_list.append(i['name'])
        import random
        random_student = random.choice(student_name_list)
        return f"{random_student} 到！"




# students().insert_student_information("faker",29,"河北省秦皇岛市",15948551330)
# update student set name = "刘闯plus",age = 29,address="河北省秦皇岛市",phone = 15948551300 where name = "刘闯"
# students().update_student_information("刘闯","刘闯plus",29,"河北省秦皇岛市",15948551330)
# print(students().point_to_student())
# students().delete_student_information("刘闯")
# print(students().show_student())
# students().update_student_information("faker","王子阳",23,"河北省沈阳市",15948554798) # age,address,phone_number
# print(students().show_student())


# 2、点餐管理系统
# 1》、餐馆可以新增菜品、下架菜品、修改菜品
# 2》、每个菜品，都有对应的库存，所有菜品的库存均为999，每出一道菜，库存-1
# 菜品有对应的价格，餐厅老板定义价格每道菜不允许超过15元，没有小数单位，均为整数
# 3》、餐馆后台有点赞系统，能够收集客户对菜品的喜好，0~5分
# 4》、有菜品评分提报功能，对平均分数（菜品总分/打分人数）低于3分的菜品进行强制下架；
class Order_Management_System:
    def __init__(self):
        self.list = []
    def addvariety_of_dishes(self,name,price):
        if price > 15:
            print("菜品添加失败")
        else:
            self.list.append({"菜品名称":name,"菜品价格":price,"库存":999,"总评分":None})
            print(f"菜品添加成功！")
    def Dishes_on_the_shelf(self,name):
        for i in self.list: #
            if i['菜品名称'] == name:
                self.list.remove(i)
        print("菜品下架成功！")
    def update_dishes(self,old_name,new_name,price):
        if price > 15:
            print("菜品修改失败！")
        else:
            for i in self.list: #
                if i['菜品名称'] == old_name:
                    self.list[i]['菜品名称'] = new_name
                    self.list[i]['菜品价格'] = price
                    self.list[i]['库存'] = 999
            print("菜品修改成功！")
    def Like_System(self,name,fraction): # 0~5分
        if fraction > 5 and fraction <0:
            print("评论失败")
        elif fraction >=0 and fraction <=5:
            for i in self.list:
                if i['菜品名称'] == name:
                    self.list[i]['总评分'] = fraction
            print("评分成功！")





#
# 客户端
# perper = 0 类属性
# 总分= 0
# 1》、客户可以进行点餐 调用父类
# 2》、每个客户的起始钱包均为200，订餐后扣减对应金额
# 3》、可以为每个菜进行打分
# class Client(Order_Management_System):
#     perper = 0 # 总人数
#     def __init__(self):
#         Order_Management_System.__init__(self)
#         self.money = 200
#         self.dishes = []
#     def Score_submission(self, name):  # 对平均分数（菜品总分/打分人数）低于3分的菜品进行强制下架；
#         for i in self.list:
#             if i['菜品']





